package com.yyj.controller;

import com.yyj.entity.*;
import com.yyj.service.CatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/*跨域*/
@CrossOrigin
@RestController
@RequestMapping("/Cat")
public class CatController {
    @Autowired
    CatService catService;

    //通过查询浏览宠物狗的信息
    @GetMapping("/searchCat")
    public Result getCat(PetParams petParams) {
        List<Pet> list = catService.getCat(petParams);
        return Result.success(list);
    }

    //用户添加动物
    @PostMapping
    public Result insertCat(@RequestBody Pet pet) {
        if (pet.getPetId() == null) {
            //添加
            catService.insertCat(pet);
            return Result.success();
        } else {
            //修改
            catService.update(pet);
            return Result.success();
        }
    }

    //用户删除发布的宠物的方法
    @DeleteMapping("/{petId}")
    public Result deletePet(@PathVariable Integer petId) {
        catService.delete(petId);
        return Result.success();
    }

    //用户更改自己的信息

}
